//
//  Picturecell.m
//  FiveWork
//
//  Created by lanou3g on 15/11/23.
//  Copyright © 2015年 Project. All rights reserved.
//

#import "Picturecell.h"
#import "JokerModel.h"
#define ScreenBounds [UIScreen mainScreen].bounds

@interface Picturecell ()
@property (nonatomic,strong) UIImageView *backImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UILabel *sourceLabel;
@property (nonatomic, strong) UIImageView *upImageView;
@property (nonatomic, strong) UIImageView *downImageView;
@property (nonatomic, strong) UILabel *upLabel;
@property (nonatomic, strong) UILabel *downLabel;
@property (nonatomic, strong) UIButton *button;
@end

@implementation Picturecell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self =[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupSubViews];
    }
    return self;
}
-(void)setupSubViews{
    self.backImageView =[[UIImageView alloc] initWithFrame:self.contentView.frame];
    [self.contentView addSubview:self.backImageView];
    self.backImageView.image =[UIImage imageNamed:@"bg_share_large"];
    
    self.contentLabel =[[UILabel alloc] initWithFrame:CGRectMake(10, 10, ScreenBounds.size.width-20, 100)];
    [self.contentLabel setNumberOfLines:0];
    [self addSubview:self.contentLabel];
    self.contentLabel.font =[UIFont systemFontOfSize:14];
    self.contentLabel.numberOfLines =0;
    
    self.sourceLabel =[[UILabel alloc] initWithFrame:CGRectMake(10, 100, 100, 30)];
    [self addSubview:self.sourceLabel];
    
//    self.upImageView =[UIImageView new];
//    [self addSubview:self.upImageView];
//    self.downImageView =[UIImageView new];
//    [self addSubview:self.downImageView];
//    self.upImageView.image = [UIImage imageNamed:@"zan"];
//    self.downImageView.image = [UIImage imageNamed:@"buzan"];

//    self.upLabel = [[UILabel alloc]init];
//    [self.upLabel setFont:[UIFont systemFontOfSize:12]];
//    [self addSubview:self.upLabel];
//    self.downLabel = [[UILabel alloc]init];
//    [self.downLabel setFont:[UIFont systemFontOfSize:12]];
//    [self addSubview:self.downLabel];
//    self.button = [UIButton buttonWithType:UIButtonTypeSystem];
//    [self addSubview:self.button];
//    [self.button setBackgroundImage:[UIImage imageNamed:@"shoucang"] forState:UIControlStateNormal];
    
  
}

-(void)setModel:(JokerModel *)model{
    if (_model !=model) {
        _model =nil;
        _model =model;
    }
    [self layoutModel];
}

-(void)layoutModel{
    
    CGRect contectRect = self.contentLabel.frame;
    CGFloat contentHeight = [[self class]textOfHeightWithText:self.model.digest font:14 width:self.contentView.frame.size.width -10];
    contectRect.size.height = contentHeight;
    self.contentLabel.frame = contectRect;
    //文字与标题的距离
    self.sourceLabel.frame = CGRectMake(10, contentHeight + 30, 100, 20);
    self.contentLabel.text = self.model.digest;
    self.sourceLabel.text = self.model.source;
    
    self.upLabel.text = [NSString stringWithFormat:@"%ld",self.model.upTimes];
    self.downLabel.text = [NSString stringWithFormat:@"%ld",self.model.downTimes];
    self.backImageView.frame = CGRectMake(5, 5, ScreenBounds.size.width - 10 , contentHeight + 55);
//    self.upLabel.frame = CGRectMake(250,contentHeight + 25 ,50 ,20 );
//    self.upImageView.frame = CGRectMake(230, contentHeight + 25, 20, 20);
//    self.downLabel.frame = CGRectMake(310,contentHeight + 25 ,25 ,20 );
//    self.downImageView.frame = CGRectMake(290, contentHeight + 25, 20, 20);
//    self.button.frame = CGRectMake(180, contentHeight + 25, 20, 20);
    
    
    
    
    
    
    
    
    
    
    
    
}

/**
 *  cell的高度
 */
+(CGFloat)heightForTextCellwWithNewsModel:(JokerModel *)model{
    CGFloat titleHeight =[self textOfHeightWithText:model.digest font:14 width:ScreenBounds.size.width -20  ];
    return 60+titleHeight;
}

/**
 *  自适应高度
 */
+(CGFloat)textOfHeightWithText:(NSString *)text font:(CGFloat)font width:(CGFloat)width
{
    CGRect rect =[text boundingRectWithSize:CGSizeMake(width, 2000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]} context:nil];
    
    
    return rect.size.height;
}





@end
